package com.yhm.barcode;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.commons.lang.RandomStringUtils;

public class createCode128 {
	public static String createCode(String code) {
		String file2 = createCode128.class.getResource("/").getPath()
				.replaceAll("WEB-INF/classes/", "temp");
		try {
			if (!new File(file2).isDirectory())
				new File(file2).mkdir();
		} catch (SecurityException e) {
			System.out.println("can   not   make   directory ");
		}
		String codeName = RandomStringUtils.randomAlphanumeric(10);
		StringBuffer sb = new StringBuffer(codeName);
		String sname = sb + ".jpeg";
		String file = file2 + "/" + sname;
		try {
			GenerateCode128Barcode.generateCode128(code, file);
			return "/temp/" + sname;
		} catch (FileNotFoundException e) {
			return null;
		} catch (IOException e) {
		}
		return null;
	}
}
